<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <script>
        let arr = [1, 2, [5, 6, [14, 6]], 5, 6, [14, [4, 6, 9]]]

        let newArr = arr.flat(Infinity)
        console.log(newArr)

        function myFlat(arr) {
            return arr.reduce((preVal, curVal) => Array.isArray(curVal) ? [...preVal, ...myFlat(curVal)] : [...preVal, curVal], [])
        }
        function myFlat1(arr) {
            return arr.reduce((preVal, curVal) => preVal.concat(Array.isArray(curVal) ? myFlat(curVal) : curVal), [])
        }

        var newArr1 = myFlat(arr)
        console.log(newArr1)
        var newArr2 = myFlat1(arr)
        console.log(newArr2)
    </script>
</body>

</html>